package com.example.onlinemonitoring.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.onlinemonitoring.model.common.*;
import com.example.onlinemonitoring.query.QueryObject;
import com.example.onlinemonitoring.Util.CommPortManager;
import com.example.onlinemonitoring.Util.LanguageManager;
import com.example.onlinemonitoring.autoRun.ComRunner;
import com.example.onlinemonitoring.autoRun.ComTcp;
import com.example.onlinemonitoring.comCenter.OilCom;
import com.example.onlinemonitoring.model.*;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import tk.mybatis.mapper.entity.Example;

import com.example.onlinemonitoring.serviceImpl.AppdeviceServiceImpl;
import com.example.onlinemonitoring.serviceImpl.OilsensorServiceImpl;

/**
 * Controller
 * 该部分代码为自动生成，请勿随意修改
 * 如有改动请删除该注释
 * 
 * @author little pig page
 * @date 2022-04-11
 */
@Api(value = "油色谱设备", tags = { "油色谱设备接口" })
@RestController
@RequestMapping("/oil")
public class OilsensorController {
    Logger logger = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
    @Autowired
    OilsensorServiceImpl oilserviceimpl;
    @Autowired
    AppdeviceServiceImpl appdeviceimpl;
    @Autowired
    LanguageManager languageManager;

    @ApiOperation(value = "修改设备", notes = "修改设备")
    @ResponseBody
    @RequestMapping(value = "/updateAll", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> updateAll(@RequestBody String jsonParam,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        Oilsensor record = object.toJavaObject(Oilsensor.class);
        MyResult<Integer> m = new MyResult<Integer>();
        record.setStationid(stationid);
        record.setDevicegroup(devicegroup);
        record.setDeviceaddr(deviceaddr);
        if (oilserviceimpl.Update(record, false) >= 1) {
            m.setMsg(languageManager.getLan().getOperationSuccess());
            m.setCode(0);
        } else {
            m.setMsg(languageManager.getLan().getOperationFailed());
            m.setCode(1);
        }
        return m;
    }

    @ApiOperation(value = "修改设备参数", notes = "修改设备参数")
    @ResponseBody
    @RequestMapping(value = "/updateAllConfig", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> updateAllConfig(@RequestBody String jsonParam,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        JSONArray li = JSONArray.parseArray(jsonParam);
        for (int i = 0; i < li.size(); i++) {
            JSONObject object = li.getJSONObject(i);
            Oilconfig record = object.toJavaObject(Oilconfig.class);
            if (oilserviceimpl.Update(record, false) == 0) {
                oilserviceimpl.Add(record);
            }
        }
        MyResult<Integer> m = new MyResult<Integer>();
        m.setMsg(languageManager.getLan().getOperationSuccess());
        m.setCode(0);
        return m;
    }

    @ApiOperation(value = "修改超出计数和O2N2H2O随机值", notes = "修改超出计数和O2N2H2O随机值")
    @ResponseBody
    @GetMapping("/updateCount")
    public MyResult<Integer> updateAllConfig(
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup,
            @RequestParam(value = "overcount", required = false) Integer overcount,
            @RequestParam(value = "o2basevalue", required = false) Float o2basevalue,
            @RequestParam(value = "n2basevalue", required = false) Float n2basevalue,
            @RequestParam(value = "h2obasevalue", required = false) Float h2obasevalue) {
        Oilconfig record = new Oilconfig();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        record.setOvercount(overcount);
        record.setO2basevalue(o2basevalue);
        record.setN2basevalue(n2basevalue);
        record.setH2obasevalue(h2obasevalue);
        oilserviceimpl.Update(record, false);
        MyResult<Integer> m = new MyResult<Integer>();
        m.setMsg(languageManager.getLan().getOperationSuccess());
        m.setCode(0);
        return m;
    }

    @ApiOperation(value = "查询系数", notes = "查询系数")
    @ResponseBody
    @GetMapping("/selectConfig")
    public MyResult<Oilconfig> selectConfig(
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        Oilconfig record = new Oilconfig();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        return oilserviceimpl.getList(record);
    }

    @ApiOperation(value = "修改设备报警", notes = "修改设备报警")
    @ResponseBody
    @RequestMapping(value = "/updateAlarm", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> updateAlarm(@RequestBody String jsonParam,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        MyResult<Integer> m = new MyResult<Integer>();
        Oilsensor record = new Oilsensor();
        record.setStationid(stationid);
        record.setDevicegroup(devicegroup);
        record.setDeviceaddr(deviceaddr);
        record.setC2h2alarmrelievevalue(object.getFloat("c2h2alarmrelievevalue"));
        record.setC2h2alarmvalue(object.getFloat("c2h2alarmvalue"));
        record.setC2h2warnrelievevalue(object.getFloat("c2h2warnrelievevalue"));
        record.setC2h2warnvalue(object.getFloat("c2h2warnvalue"));
        record.setC2h4alarmrelievevalue(object.getFloat("c2h4alarmrelievevalue"));
        record.setC2h4alarmvalue(object.getFloat("c2h4alarmvalue"));
        record.setC2h4warnrelievevalue(object.getFloat("c2h4warnrelievevalue"));
        record.setC2h4warnvalue(object.getFloat("c2h4warnvalue"));
        record.setC2h6alarmrelievevalue(object.getFloat("c2h6alarmrelievevalue"));
        record.setC2h6alarmvalue(object.getFloat("c2h6alarmvalue"));
        record.setC2h6warnrelievevalue(object.getFloat("c2h6warnrelievevalue"));
        record.setC2h6warnvalue(object.getFloat("c2h6warnvalue"));
        record.setCh4alarmrelievevalue(object.getFloat("ch4alarmrelievevalue"));
        record.setCh4alarmvalue(object.getFloat("ch4alarmvalue"));
        record.setCh4warnrelievevalue(object.getFloat("ch4warnrelievevalue"));
        record.setCh4warnvalue(object.getFloat("ch4warnvalue"));
        record.setCo2alarmrelievevalue(object.getFloat("co2alarmrelievevalue"));
        record.setCo2alarmvalue(object.getFloat("co2alarmvalue"));
        record.setCo2warnrelievevalue(object.getFloat("co2warnrelievevalue"));
        record.setCo2warnvalue(object.getFloat("co2warnvalue"));
        record.setCoalarmrelievevalue(object.getFloat("coalarmrelievevalue"));
        record.setCoalarmvalue(object.getFloat("coalarmvalue"));
        record.setCowarnrelievevalue(object.getFloat("cowarnrelievevalue"));
        record.setCowarnvalue(object.getFloat("cowarnvalue"));
        record.setGascontentalarmrelievevalue(object.getFloat("gascontentalarmrelievevalue"));
        record.setGascontentalarmvalue(object.getFloat("gascontentalarmvalue"));
        record.setGascontentwarnrelievevalue(object.getFloat("gascontentwarnrelievevalue"));
        record.setGascontentwarnvalue(object.getFloat("gascontentwarnvalue"));
        record.setH2alarmrelievevalue(object.getFloat("h2alarmrelievevalue"));
        record.setH2alarmvalue(object.getFloat("h2alarmvalue"));
        record.setH2warnrelievevalue(object.getFloat("h2warnrelievevalue"));
        record.setH2warnvalue(object.getFloat("h2warnvalue"));
        record.setN2alarmrelievevalue(object.getFloat("n2alarmrelievevalue"));
        record.setN2alarmvalue(object.getFloat("n2alarmvalue"));
        record.setN2warnrelievevalue(object.getFloat("n2warnrelievevalue"));
        record.setN2warnvalue(object.getFloat("n2warnvalue"));
        record.setO2alarmrelievevalue(object.getFloat("o2alarmrelievevalue"));
        record.setO2alarmvalue(object.getFloat("o2alarmvalue"));
        record.setO2warnrelievevalue(object.getFloat("o2warnrelievevalue"));
        record.setO2warnvalue(object.getFloat("o2warnvalue"));
        record.setPpmalarmrelievevalue(object.getFloat("ppmalarmrelievevalue"));
        record.setPpmalarmvalue(object.getFloat("ppmalarmvalue"));
        record.setPpmwarnrelievevalue(object.getFloat("ppmwarnrelievevalue"));
        record.setPpmwarnvalue(object.getFloat("ppmwarnvalue"));
        record.setPressurealarmrelievevalue(object.getFloat("pressurealarmrelievevalue"));
        record.setPressurealarmvalue(object.getFloat("pressurealarmvalue"));
        record.setPressurewarnrelievevalue(object.getFloat("pressurewarnrelievevalue"));
        record.setPressurewarnvalue(object.getFloat("pressurewarnvalue"));
        record.setTemperaturealarmrelievevalue(object.getFloat("temperaturealarmrelievevalue"));
        record.setTemperaturealarmvalue(object.getFloat("temperaturealarmvalue"));
        record.setTemperaturewarnrelievevalue(object.getFloat("temperaturewarnrelievevalue"));
        record.setTemperaturewarnvalue(object.getFloat("temperaturewarnvalue"));
        record.setTothydalarmrelievevalue(object.getFloat("tothydalarmrelievevalue"));
        record.setTothydalarmvalue(object.getFloat("tothydalarmvalue"));
        record.setTothydwarnrelievevalue(object.getFloat("tothydwarnrelievevalue"));
        record.setTothydwarnvalue(object.getFloat("tothydwarnvalue"));
        if (oilserviceimpl.Update(record, false) >= 1) {
            m.setMsg(languageManager.getLan().getOperationSuccess());
            m.setCode(0);
        } else {
            m.setMsg(languageManager.getLan().getOperationFailed());
            m.setCode(1);
        }
        return m;
    }

    @ApiOperation(value = "查询实时表数据", notes = "查询实时表数据")
    @ResponseBody
    @GetMapping("/selectSensorData")
    public MyResult<Oilsensor> selectSensorData(
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "limit", required = false) Integer limit,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        Oilsensor record = new Oilsensor();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        QueryObject qo = new QueryObject(page, limit);
        String column[] = { "id",
                "transformergroupid",
                "stationid",
                "devicegroup",
                "deviceaddr",
                "pointname",
                "lasth2",
                "lastco",
                "lastco2",
                "lastch4",
                "lastn2",
                "lastc2h4",
                "lastc2h2",
                "lastc2h6",
                "lasto2",
                "lasttothyd",
                "lastpressure",
                "lasttemperature",
                "lasttemperaturectrl1",
                "lasttemperaturectrl2",
                "lastgascontent",
                "lasth2o",
                "lastppm",
                "lastoiltemp",
                "ppmalarmrelievevalue",
                "ppmalarmvalue",
                "ppmwarnrelievevalue",
                "ppmwarnvalue",
                "pressurealarmrelievevalue",
                "pressurealarmvalue",
                "pressurewarnrelievevalue",
                "pressurewarnvalue",
                "gascontentalarmrelievevalue",
                "gascontentalarmvalue",
                "gascontentwarnrelievevalue",
                "gascontentwarnvalue",
                "temperaturealarmrelievevalue",
                "temperaturealarmvalue",
                "temperaturewarnrelievevalue",
                "temperaturewarnvalue",
                "tothydalarmrelievevalue",
                "tothydalarmvalue",
                "tothydwarnrelievevalue",
                "tothydwarnvalue",
                "c2h6alarmrelievevalue",
                "c2h6alarmvalue",
                "c2h6warnrelievevalue",
                "c2h6warnvalue",
                "c2h2alarmrelievevalue",
                "c2h2alarmvalue",
                "c2h2warnrelievevalue",
                "c2h2warnvalue",
                "c2h4alarmrelievevalue",
                "c2h4alarmvalue",
                "c2h4warnrelievevalue",
                "c2h4warnvalue",
                "ch4alarmrelievevalue",
                "ch4alarmvalue",
                "ch4warnrelievevalue",
                "ch4warnvalue",
                "co2warnrelievevalue",
                "co2alarmrelievevalue",
                "co2alarmvalue",
                "co2warnvalue",
                "cowarnvalue",
                "cowarnrelievevalue",
                "coalarmvalue",
                "coalarmrelievevalue",
                "h2warnvalue",
                "h2warnrelievevalue",
                "h2alarmvalue",
                "h2alarmrelievevalue",
                "n2warnvalue",
                "n2warnrelievevalue",
                "n2alarmvalue",
                "n2alarmrelievevalue",
                "o2warnvalue",
                "o2warnrelievevalue",
                "o2alarmvalue",
                "o2alarmrelievevalue",
                "lastdatatime",
                "lastcommunicationstatus",
                "lastalarmmessage",
                "lastalarmlevel",
                "memo",
                "style",
                "inuse",
                "lastppmalarmstatus",
                "lasth2alarmstatus",
                "lasto2alarmstatus",
                "lastn2alarmstatus",
                "lastch4alarmstatus",
                "lastc2h2alarmstatus",
                "lastc2h4alarmstatus",
                "lastc2h6alarmstatus",
                "lastcoalarmstatus",
                "lastco2alarmstatus",
                "lasttothydalarmstatus",
                // "lastorigindata",
                // "lastprocesseddata",
                // "lastelem",
                "start",
                "end",
                "simulate",
                "simulateauto",
                "count",
                "quality",
                "density",
                "o2basevalue",
                "n2basevalue",
                "h2obasevalue" };
        return oilserviceimpl.getList(record, qo, column);
    }

    @ApiOperation(value = "查询实时表谱图", notes = "查询实时表谱图")
    @ResponseBody
    @GetMapping("/selectSensorSpecgram")
    public MyResult<Oilsensor> selectSensorSpecgram(
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "limit", required = false) Integer limit,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        Oilsensor record = new Oilsensor();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        QueryObject qo = new QueryObject(page, limit);
        return oilserviceimpl.getList(record, qo);
    }

    @ApiOperation(value = "修改监测点名称", notes = "修改监测点名称")
    @ResponseBody
    @RequestMapping(value = "/updateMonitorName", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> updateMonitorName(@RequestBody String jsonParam,
            @RequestParam(value = "id", required = false) Long id) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        MyResult<Integer> m = new MyResult<Integer>();
        Oilsensor record = new Oilsensor();
        record.setId(id);
        record.setPointname(object.getString("pointname"));
        if (oilserviceimpl.Update(record, true) >= 1) {
            m.setMsg(languageManager.getLan().getOperationSuccess());
            m.setCode(0);
        } else {
            m.setMsg(languageManager.getLan().getOperationFailed());
            m.setCode(1);
        }
        return m;
    }

    @ApiOperation(value = "查询历史表数据", notes = "查询历史表数据")
    @ResponseBody
    @GetMapping("/selectHistoryData")
    public MyResult<Oilhistory> selectHistoryData(
            @RequestParam(value = "page", required = true) Integer page,
            @RequestParam(value = "limit", required = true) Integer limit,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup,
            @RequestParam(value = "start", required = false) String begintime,
            @RequestParam(value = "end", required = false) String endtime,
            @RequestParam(value = "pagecount", required = false) Integer pagecount) {
        Oilhistory record = new Oilhistory();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        pagebase pagebase = new pagebase();
        pagebase.setBegintime(begintime);
        pagebase.setEndtime(endtime);
        pagebase.setPage(page);
        pagebase.setLimit(limit);
        pagebase.setPagecount(pagecount);
        String column[] = { "id",
                "stationid",
                "devicegroup",
                "deviceaddr",
                "pointname",
                "h2",
                "co",
                "co2",
                "ch4",
                "c2h4",
                "c2h2",
                "n2",
                "c2h6",
                "o2",
                "tothyd",
                "pressure",
                "temperature",
                "temperaturectrl1",
                "temperaturectrl2",
                "gascontent",
                "h2o",
                "ppm",
                "oiltemp",
                "datatime",
                "communicationstatus",
                "alarmlevel",
                "alarmmessage",
                // "origindata",
                // "processeddata",
                // "elem"
        };
        return oilserviceimpl.getHisList(record, pagebase, column);
    }

    @ApiOperation(value = "查询历史表谱图", notes = "查询历史表谱图")
    @ResponseBody
    @GetMapping("/selectHistorySpecgram")
    public MyResult<Oilhistory> selectHistorySpecgram(
            @RequestParam(value = "page", required = true) Integer page,
            @RequestParam(value = "limit", required = true) Integer limit,
            @RequestParam(value = "id", required = false) Integer id,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup,
            @RequestParam(value = "start", required = false) String begintime,
            @RequestParam(value = "end", required = false) String endtime,
            @RequestParam(value = "pagecount", required = false) Integer pagecount) {
        Oilhistory record = new Oilhistory();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        pagebase pagebase = new pagebase();
        pagebase.setBegintime(begintime);
        pagebase.setEndtime(endtime);
        pagebase.setPage(page);
        pagebase.setLimit(limit);
        pagebase.setPagecount(pagecount);
        if (id != null) {
            return oilserviceimpl.getHisListById(record, pagebase, id);
        } else {
            return oilserviceimpl.getHisList(record, pagebase);
        }
    }

    @ApiOperation(value = "查询历史表曲线", notes = "查询历史表曲线")
    @ResponseBody
    @GetMapping("/selectHistoryCurve")
    public MyResult<chartres> selectHistoryCurve(
            @RequestParam(value = "page", required = true) Integer page,
            @RequestParam(value = "limit", required = true) Integer limit,
            @RequestParam(value = "stationid", required = true) Integer stationid,
            @RequestParam(value = "devicegroup", required = true) Integer devicegroup,
            @RequestParam(value = "deviceaddr", required = true) Integer deviceaddr,
            @RequestParam(value = "start", required = false) String begintime,
            @RequestParam(value = "end", required = false) String endtime,
            @RequestParam(value = "pagecount", required = false) Integer pagecount,
            @RequestParam(value = "lstr", required = false) String lstr) {

        Oilhistory record = new Oilhistory();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        pagebase pagebase = new pagebase();
        pagebase.setBegintime(begintime);
        pagebase.setEndtime(endtime);
        pagebase.setPage(page);
        pagebase.setLimit(limit);
        pagebase.setIsasc(true);
        pagebase.setPagecount(pagecount);
        return oilserviceimpl.getHisCurveList(record, lstr, pagebase);
    }

    @ApiOperation(value = "油色谱控制", notes = "油色谱控制")
    @ResponseBody
    @GetMapping("/cmdDevice")
    public MyResult<String> cmdDevice(
            @RequestParam(value = "stationid", required = true) Integer stationid,
            @RequestParam(value = "devicegroup", required = true) Integer devicegroup,
            @RequestParam(value = "deviceaddr", required = true) Integer deviceaddr,
            @RequestParam(value = "cmd", required = true) Integer cmd,
            @RequestParam(value = "count", required = false) Integer count,
            @RequestParam(value = "hours1", required = false) Integer hours1,
            @RequestParam(value = "minutes1", required = false) Integer minutes1,
            @RequestParam(value = "hours2", required = false) Integer hours2,
            @RequestParam(value = "minutes2", required = false) Integer minutes2,
            @RequestParam(value = "hours3", required = false) Integer hours3,
            @RequestParam(value = "minutes3", required = false) Integer minutes3,
            @RequestParam(value = "hours4", required = false) Integer hours4,
            @RequestParam(value = "minutes4", required = false) Integer minutes4,
            @RequestParam(value = "targetaddr", required = false) Integer targetaddr,
            @RequestParam(value = "targetpoint", required = false) Integer targetpoint) {
        Appdevice record = new Appdevice();
        Example example = new Example(Appdevice.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stationid", stationid);
        criteria.andEqualTo("devicegroup", devicegroup);
        criteria.andEqualTo("simple", "oil");
        record = appdeviceimpl.selectOneByExample(example);
        int index = 0;
        OilCom oc = null;
        switch (record.getCommunicationmode()) {
            case 1:
                index = CommPortManager.strGetNum(record.getCom());
                oc = (OilCom) ComRunner.devmap.get(index);
                break;
            case 2:
                index = record.getId();
                oc = (OilCom) ComRunner.netmap.get(index);
                break;
            case 3:
                index = record.getId();
                oc = (OilCom) ComRunner.netservermap.get(index);
                break;
            default:
                break;
        }

        if (oc == null) {
            return new MyResult<String>(1, languageManager.getLan().getMsg6());
        }
        MyResult<String> res = new MyResult<>();

        // 每次发送控制之前就清空返回
        oc.setControllerRet("");
        String cstr = "";
        cstr = oc.CreateCommand(deviceaddr, cmd, count, hours1, minutes1, hours2, minutes2, hours3, minutes3, hours4,
                minutes4, targetaddr, targetpoint,
                false);
        oc.ControlCommand(cstr);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } // 等待接收线程接收完数据
        if (!oc.getControllerRet().equals("")) {
            List<String> l = new ArrayList<String>();
            l.add(oc.getControllerRet());
            res.setData(l);
            res.setCode(0);
            res.setMsg(languageManager.getLan().getOperationSuccess());
            return res;
        }
        res.setCode(1);
        res.setMsg(languageManager.getLan().getOperationFailed());
        return res;
    }

    @ApiOperation(value = "查询产气率", notes = "查询产气率")
    @ResponseBody
    @GetMapping("/selectPuerperalRate")
    public MyResult<float[][]> selectPuerperalRate(
            @RequestParam(value = "stationid", required = true) Integer stationid,
            @RequestParam(value = "deviceaddr", required = true) Integer deviceaddr,
            @RequestParam(value = "devicegroup", required = true) Integer devicegroup,
            @RequestParam(value = "begintime", required = true) String begintime,
            @RequestParam(value = "endtime", required = true) String endtime) {

        Oilhistory record = new Oilhistory();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        pagebase pagebase = new pagebase();
        pagebase.setPage(1);
        pagebase.setLimit(10000);
        pagebase.setBegintime(begintime);
        pagebase.setEndtime(endtime);
        return oilserviceimpl.getPuerperalRate(record, pagebase);
    }

    /**
     * 导出Excel
     */
    @GetMapping("exportToExcel")
    public void exportToExcel(HttpServletResponse response,
            @RequestParam(value = "stationid", required = true) Integer stationid,
            @RequestParam(value = "devicegroup", required = true) Integer devicegroup,
            @RequestParam(value = "deviceaddr", required = true) Integer deviceaddr,
            @RequestParam(value = "start", required = false) String begintime,
            @RequestParam(value = "end", required = false) String endtime) throws IOException {
        Oilhistory record = new Oilhistory();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        pagebase pagebase = new pagebase();
        pagebase.setBegintime(begintime);
        pagebase.setEndtime(endtime);
        Workbook wb = oilserviceimpl.writeToExcelByList(record, pagebase);
        OutputStream output = response.getOutputStream();
        String fileName = "data.xlsx";
        try {
            fileName = URLEncoder.encode(fileName, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        response.setHeader("Content-disposition",
                "attachment;filename=" + fileName + ";" + "filename*=utf-8''" + fileName);
        wb.write(output);
        output.close();
    }
    // @ApiOperation(value = "查询实时波形谱图", notes = "查询实时波形谱图")
    // @ResponseBody
    // @GetMapping("/selectSpectrogram")
    // public MyResult<chartres> selectSpectrogram(
    // @RequestParam(value = "stationid", required = true) Integer stationid,
    // @RequestParam(value = "devicegroup", required = true) Integer devicegroup,
    // @RequestParam(value = "deviceaddr", required = true) Integer deviceaddr,
    // @RequestParam(value = "start", required = false) String begintime,
    // @RequestParam(value = "end", required = false) String endtime,
    // @RequestParam(value = "pagecount", required = false) Integer pagecount) {

    // Oilhistory record = new Oilhistory();
    // record.setStationid(stationid);
    // record.setDeviceaddr(deviceaddr);
    // record.setDevicegroup(devicegroup);
    // pagebase pagebase = new pagebase();
    // pagebase.setBegintime(begintime);
    // pagebase.setEndtime(endtime);
    // pagebase.setIsasc(true);
    // pagebase.setPagecount(pagecount);
    // return oilserviceimpl.getHisCurveList(record, lstr, pagebase);
    // }
    /**
     * 导出Excel
     */
    @GetMapping("exportToSensorExcel")
    public void exportToSensorExcel(HttpServletResponse response,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr) throws IOException {
        Oilsensor record = new Oilsensor();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        Workbook wb = oilserviceimpl.writeToExcelBySensorList(record);
        OutputStream output = response.getOutputStream();
        String fileName = "data.xlsx";
        try {
            fileName = URLEncoder.encode(fileName, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        response.setHeader("Content-disposition",
                "attachment;filename=" + fileName + ";" + "filename*=utf-8''" + fileName);
        wb.write(output);
        output.close();
    }
}
